package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.jt.tenant.widget.Tools;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/7.
 */
@HttpInlet(Conn.INLET_INDEX)
public class GetIndex extends JTAsyGet<GetIndex.Info> {

    public String token = JTApplication.jtPreferences.readToken();

//    public String obdid = JTApplication.jtPreferences.readOdbID();

    public String lon;

    public String lat;

    public GetIndex(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        JSONObject body = apiTYF.optJSONObject("body");

        JSONObject index = body.optJSONObject("index");

        Info info = new Info();

        info.msg = head.optString("msg");

        info.score = index.optString("score");

        info.scoreDate = index.optString("scoreDate");

        info.extent = index.optString("extent");

        info.baoxianFlag = body.optString("baoxianFlag");

        info.egsFlag = body.optString("egsFlag");

        info.version = body.optString("version");

        info.downloadPath = body.optString("downloadPath");

        info.integralCount = Tools.F_num(index.optString("integralCount"));

        info.commonCount = Tools.F_num(index.optString("commonCount"));

        JSONArray codeList = index.optJSONArray("codeList");

        if(codeList != null){

            for(int i = 0;i<codeList.length();i++){

                String code = new String();

                JSONObject mCode = codeList.optJSONObject(i);

                code = mCode.optString("code");

                info.Fault_code.add(code);

            }

        }

        JSONArray payList = index.optJSONArray("list");

        if(payList != null){

            for(int j = 0;j<payList.length();j++) {

                PayType payType = new PayType();

                JSONObject mPaytype = payList.optJSONObject(j);

                payType.name = mPaytype.optString("mentName");

                payType.flag = mPaytype.optString("flag");

                info.Pay_List.add(payType);

            }

        }

        return info;

    }

    public static class Info {

        public String msg;

        public String baoxianFlag,egsFlag,version,downloadPath;

        public String score, scoreDate,extent,integralCount,commonCount;

        public List<String> Fault_code = new ArrayList<>();

        public List<PayType> Pay_List = new ArrayList<>();

    }

    public static class PayType{

        String name;

        String flag;

    }

}
